package com.zzh.model.builder;

/**
 * @author zhangzhihao
 * @email zhangzhihao@gongjiangren.net
 * @date 2020-11-14
 * @desc 现在发现的唯一好处就是 不用关心最终生成的对象的建造过程 和内部建造需要的顺序
 */
public class BuilderDemo {

    private String name;
    private String value;
    private String age;

    public String getValue() {
        return value;
    }

    public String getName() {
        return name;
    }

    public String getAge() {
        return age;
    }

    public void setValue(String value) {
        this.value = value;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setAge(String age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "BuilderDemo{" +
                "name='" + name + '\'' +
                ", value='" + value + '\'' +
                ", age='" + age + '\'' +
                '}';
    }

    public void show() {
        System.out.println(toString());
    }


    public static class MyBuilder {

        private String name;
        private String value;
        private String age;

        public MyBuilder setName(String name) {
            this.name = name;
            return this;
        }

        public MyBuilder setValue(String value) {
            this.value = value;
            return this;
        }

        public MyBuilder setAge(String age) {
            this.age = age;
            return this;
        }

        public BuilderDemo create() {
            BuilderDemo builderDemo = new BuilderDemo();
            builderDemo.setName(name);
            builderDemo.setValue(value);
            builderDemo.setAge(age);
            return builderDemo;
        }
    }

}
